<div id="subContainer" class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>合作单位维护</h5>
            <div class="ibox-tools">
                <div class="ibox-tools">
                    <a :href="applicationContextRootPath + 'pages/company/add.html'"
                       data-pjax class="btn btn-primary btn-xs">新增</a>
                </div>
            </div>
        </div>
        <div class="ibox-content">

            <div class="row">
                <div class="col-sm-3" v-for="(filter, index) in searchParams.filters" :key="index" v-if="filter.showAble">
                    <div class="input-group">
                        <input type="text" placeholder="请输入关键词" class="input-sm form-control search-input"
                               v-model="filter.fieldValue" v-bind:fieldName="filter.fieldName"
                               v-bind:fieldValue="filter.fieldValue"
                               v-bind:compare="filter.compare"
                               :disabled="filter.readonly"
                               @keyup.enter.native="search"
                               :placeholder="filter.placeholder" :readonly="filter.readonly" clearable>
                    </div>
                </div>
                <div class="input-group">
                            <span class="input-group-btn">
                                                <button type="button" class="btn btn-sm btn-primary"
                                                        v-on:click="pagequery()"> 搜索</button> </span>
                </div>
            </div>

            <div class="table-responsive">
                <table class="table table-striped">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>合作单位</th>
                        <th>法人姓名</th>
                        <th>联系电话</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr v-for="(item, index) in items">
                        <th scope="row">{{(searchParams.pageNum - 1) * 10 + index + 1}}</th>
                        <td>{{item.name}}</td>
                        <td>{{item.contacts}}</td>
                        <td>{{item.tel}}</td>
                        <td>
                            <button type="button" v-on:click="deleteItem(item)" class="btn btn-danger btn-xs">
                                删除
                            </button>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
            <pageination :total="searchParams.total" :size="searchParams.pageSize" :page="searchParams.page"
                         :changge="pageFn"></pageination>

        </div>
    </div>

</div>

<script src="/js/validateIsMain.js"></script>
<script>
    var vue = new Vue({
        el: '#subContainer',
        data: {
            applicationContextRootPath: '/',
            searchParams: {
                orderBy: 'update_at desc',
                page: 1,
                pageSize: 10,
                filters: [
                    {
                        showAble: true,
                        readonly: false,
                        placeholder: "合作单位",
                        fieldName: "name",
                        compare: "like",
                        fieldValue: ""
                    },
                    {
                        showAble: true,
                        readonly: false,
                        placeholder: "法人姓名",
                        fieldName: "contacts",
                        compare: "like",
                        fieldValue: ""
                    }
                ],
                isLock: ''
            },
            items: [{}],
            master: [],//接受权限数组
            result: false,//表示超级管理员权限
            resultDev: false,//表示操作人员权限
        },
        created: function () {
            this.loginMaster();
            this.pagequery();
        },
        methods: {
            pagequery: function () {
                var that = this;
                AJAX.POST_JSON('/api/sysCompany/index', this.searchParams, function (resp) {
                    that.items = resp.data.records;
                    that.searchParams.pageNum = resp.data.current;
                    that.searchParams.total = resp.data.total;
                })
            },
            pageFn: function (val) {
                this.searchParams.pageNum = val;
                this.pagequery();
            },
            edit: function (item) {
                sessionStorage.setItem('editParams', item.id);
                $.pjax({
                    url: mvm.applicationContextRootPath + 'pages/company/edit.html',
                    container: '.page-container'
                });
            },
            deleteItem: function(item){
                var that = this;
                confirm("您确定要删除这个单位吗?", "", function (isConfirm) {
                    if (isConfirm) {
                        AJAX.DELETE('/api/sysCompany', item, function (resp) {
                            toastr.success(resp.msg);
                            that.pagequery();
                        })
                    } else {
                        //after click the cancel
                    }
                }, {confirmButtonText: '确认', cancelButtonText: '取消', width: 400});
            }
        }
    });
</script>
